# # # # $gp ($28) contains 0x1000 8000 and points the middle of the 1st 2^16 bytes (64k) covering [0x1000 0000, 0x1001 0000] .extern _x 4 # 4 is the size; address 0x1000 0000 (dec 268435456) # -32768($28) gives address 0x1000 0000 .extern _y 4 # 4 is the size; address 0x1000 0008 (dec 268435464) # -32760($28) gives address 0x1000 0008 _x: .word 6 # _x isn’t initialised .data 0x10010000 # This is the upper bound of the 1st 2^16 bytes (64k) covering [0x1000 0000, 0x1001 0000] .align 2 .globl g a: .word 5 # address 0x1001 0000 g: .word 7 # address 0x1001 0004 _y: .word 9 # address is 0x1001 0008 (dec 268501000); this _y is different from .extern _y label1: .asciiz "\nHello, have a nice day.\n" #string to print lineF: .asciiz "\n\n" .text .globl main main: # main has to be a global label addu $s7, $0, $ra # save the return address in a register lw $s3, a lw $s4, g sw $s3, _x # access .extern _x := a lw $s1, _x # access .extern _x # -32768($28) gives address 0x1000 0000 la $t1, _x # gets address of .extern _x; this instruction is assembled to ori $9, $28, -32768 li $s6, 3 sw $s6, -32764($28) # -32764($28) gives address 0x1000 0004 sw $s4, _y # access .extern _y := g lw $s2, _y # access .extern _y la $t2, _y # gets address of local _y (0x1001 0008) not address of .extern _y (0x1000 0008); this instruction is assembled to ori $1, $0, -32760 and add $10, $28, $1 lw $s5, 0($t2) li $v0, 4 # print_str (system call 4) la $a0, label1 # takes string address as an argument syscall #Print line break li $v0, 11 li $a0, 10 # 0x0a (LineFeed) syscall li $v0, 1 # print_int (system call 1) move $a0, $s1 # takes the integer as an argument syscall #Print line break # Print line break using syscall service 11 li $v0, 4 # li $v0, 11 la $a0, lineF # li $a0, 10 # 0x0a (LineFeed) syscall # syscall li $v0, 1 # print_int (system call 1) move $a0, $s2 # takes the integer as an argument syscall li $v0, 4 la $a0, lineF syscall li $v0, 1 move $a0, $s5 syscall li $v0, 4 la $a0, lineF syscall li $v0, 1 move $a0, $t1 syscall li $v0, 4 la $a0, lineF syscall li $v0, 1 move $a0, $t2 syscall #------------Usual stuff at the end of the main addu $ra, $0, $s7 # restore the return address jr $ra # return to the main program # add $0, $0, $0 # nop (does not do anything here)